package com.lfnyxy.service.imp;

import com.lfnyxy.dao.ServerDao;
import com.lfnyxy.entity.ServerEntity;
import com.lfnyxy.query.ServerQuery;
import com.lfnyxy.service.ServerService;
import com.lfnyxy.vo.ServerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServerServiceImp implements ServerService {
    @Autowired
    public ServerDao serverDao;

    public int CreateItem(ServerEntity entity) {
        if (entity != null) {
//            if (CheckIsExist(entity)) {
//                return -1;
//            }
            return serverDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(ServerEntity entity) {
        if (entity != null) {
//            if (CheckIsExist(entity)) {
//                return -1;
//            }
            return serverDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List <ServerVo> QueryPageList(ServerQuery query) {
        int count = serverDao.QueryPageListCount(query);
        query.setTotal(count);
        return serverDao.QueryPageList(query);
    }

    public List <ServerEntity> QueryAll() {
        return serverDao.QueryAll();
    }

    public ServerEntity QueryItem(int Id) {
        if (Id > 0) {
            return serverDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return serverDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(ServerEntity entity) {
        if (entity != null) {
            return serverDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}